/**
 * 获取优惠券信息列表
 * @param query
 */
function getCouponData(query) {
    $('#CouponList')
        .DataTable(
            {
                "destroy": true,
                // "searching":false,
                "pagingType": "full_numbers",
                "sLoadingRecords": "正在加载数据...",
                "sZeroRecords": "暂无数据",
                "ajax": {
                    url: "/coupon/getCouponList",
                    // dataSrc: 'data',//原来为空，修改为data 因为服务端模式返回的是data入参
                    dataSrc: "",
                    type:"post",
                    data : query,
                },
                // "serverSide": true,//服务端分页
                // "lengthChange": false,//是否允许用户自定义显示数量
                // "scrollY": "360px",//竖向滚动条
                // "scrollCollapse": "true",//是否出现滚动条
                // 'iDisplayLength':50,
                "searching": true,
                "columns": [
                    {
                        "data": "id"
                    },
                    {
                        "data": "name"
                    },
                    {
                        "data": "content"
                    },
                    {
                        "data": "percentage"
                    },
                    {
                        "data": "status"
                    },
                    {
                        "data": "startTime"
                    },
                    {
                        "data": "endTime"
                    },
                    {
                        "data": "createTime"
                    },
                    {
                        "data": "updateTime"
                    },
                    {
                        "data": null,
                        "render": function (data, type, row, meta) {
                            var html = "<a  href='#' role='button' class='btn btn-success btn-xs btn-green' data-toggle='modal' onclick='modifyCouponDialog("
                                + JSON.stringify(row)
                                + ")'><i class='fa fa-pencil' ></i>修改</a>    "

                                + '<a href="#" role="button" class=\'btn btn-danger btn-xs btn-remove\' data-toggle="modal"  onclick="deleteCouponData('
                                + row.id
                                + ')"><i class="fa fa-trash-o"  ></i>删除</a>  ';

                            return html;
                        }
                    }
                ],
                "language": {
                    "processing": "玩命加载中...",
                    "lengthMenu": "显示 _MENU_ 项结果",
                    "zeroRecords": "没有匹配结果",
                    "info": "显示第 _START_ 至 _END_ 项结果，共 _TOTAL_ 项",
                    "infoEmpty": "显示第 0 至 0 项结果，共 0 项",
                    "infoFiltered": "(由 _MAX_ 项结果过滤)",
                    "infoPostFix": "",
                    "url": "",
                    "paginate": {
                        "first": "首页",
                        "previous": "前一页",
                        "next": "下一页",
                        "last": "末页"
                    }
                }
            });
}

/**
 * 刷新
 */
function refreshCouponData() {
    var b = {
        'id': $("#searchCouponId").val() != "" ? $("#searchCouponId").val() : 0,
        'name': $("#searchCouponName").val(),
        'content': $("#searchCouponContent").val(),
        // "limit":1,
        // "page":1
    };
    $.ajax({
        // 请求方式
        type: "post",
        // 请求地址
        url: "/coupon/getCouponList",
        data: JSON.stringify(b),
        contentType: 'application/json;charset=UTF-8',
        success: function (result) {
            b.recordsTotal=result;
            getCouponData(b);
        },
        error: function (e) {
            console.log(e.status);
            console.log(e.responseText);
            alert("操作有误请联系管理员")
        }
    });
}